home *** CD-ROM | disk | FTP | other *** search
Text File | 2002-05-10 | 31.3 KB | 1,085 lines |
- // Constants
- // Type Edit Box
- var i32x e_GUI_EditBox_All = 0;
- var i32x e_GUI_EditBox_CharOnly = 1;
- var i32x e_GUI_EditBox_Numeric = 2;
- var i32x e_GUI_EditBox_Chat = 3;
-
- // Change EditBox
- var i32x e_GUI_EditBox_Change_True = 0;
- var i32x e_GUI_EditBox_Change_False = 1;
-
- // editbox.cnh
- message SaveData(Gui_Component _pComponent, szx _szTxt, i32x _iChangeBox);
-
-
- // Standard editbox
- // Data class
- class Gui_dtEditBox
- {
- var i32x iCursor; // cursor position
- var i32x iCursorEndSelect; // cursor position at the end of selection
- var i32x iMaxChar; // size edit box
- var i32x iType; // All, char only, int only
- var szx szTxt; // edit box contains this text
- var boolx bClick; // true if click down, false if click up
- var boolx bInsert; // if insert mode
- var boolx bWrite; // write or not
- var boolx bShift; // true if key down = shift
- };
-
- class Gui_dtEditBoxComposite
- {
- var Gui_Component gcEditBox; // edit box
- var Gui_Component gcCursor; // cursor
- var Gui_Component gcTexture; // background texture
- var i32x iLenghtCursor; // cursor size
- var i32x iHeightCursor; // cursor height
- var i32x iHAlign; // Default Horizontal align
- var i32x iVAlign; // Default vertical align
- var i32x iFocused; // Cursor shown ?
- var f32x fFontFactor; // factor font size
- };
-
- // Message
- // edit box
- message EbText(szx _szTxt);
- message EbChangeType(i32x _iType);
- message EbNbCharAccepted(i32x _iSize);
- message EbResize(i32x _iX, i32x _iY);
-
- // edit box composite
- message EbCText(szx _szTxt);
- message EbCChangeType(i32x _iType);
- message EbCNbCharAccepted(i32x _iSize);
- message EbCClick(i32x _iX,i32x _iY,i32x _iButton);
- message EbCDblClick();
- message EbCLoseFocus();
- message EbCGainFocus();
- message EbCMoveCursor(i32x _iCase);
- message EbCMoveCursorSelect(i32x _iCase);
- message EbCMouseMove(i32x _iX, i32x _iY);
- message EbCSaveData(szx _szTxt, i32x _iChangeBox);
- message EbCResize(i32x _iX, i32x _iY);
- message EbCAlign(i32x _eHAlign, i32x _eVAlign);
- message EbCChangeColor(i32x _iColor);
-
- // Init func Predeclaration
- func Gui_Component NewEditBox(Menu_Material _pFont, i32x _iColor);
- func Gui_Component NewEditBoxExt(Menu_Material _pFont, i32x _iColor, f32x _fFontSize);
-
- // Predeclaration
- // event edit box
- func i32x EditBox_OnMouseClick(i32x _iX,i32x _iY,i32x _iButton);
- func void EditBox_OnKeyDown(i32x _iKey, i32x _iCount);
- func void EditBox_OnChar(szx _szChar,i32x _iCount);
- func i32x EditBox_OnLoseFocus();
- func i32x EditBox_OnGainFocus();
- func i32x EditBox_OnKeyUp(i32x _iKey);
- func i32x EditBox_OnMouseDown(i32x _iX,i32x _iY,i32x _iButton);
- func i32x EditBox_OnMouseUp(i32x _iX,i32x _iY,i32x _iButton);
- func i32x EditBox_OnMouseMove(i32x _iX,i32x _iY);
- func i32x EditBox_OnMouseDblClick(i32x _iX,i32x _iY,i32x _iButton);
-
- // msg edit box
- func void EditBox_Text(szx _szTxt);
- func void EditBox_SetText(Gui_Component _pthis, Gui_dtEditBox _pdtEditBox, szx _szTxt);
- func szx EditBox_GetText(Gui_Component _pComponent);
- func void EditBox_ChangeType(i32x _iType);
- func void EditBox_NbCharAccepted(i32x _iSize);
- func void EditBox_Resize(i32x _iX, i32x _iY);
-
- // event edit box composite
- func void EditBoxComposite_OnClick(i32x _iX,i32x _iY,i32x _iButton);
- func void EditBoxComposite_OnLoseFocus();
- func void EditBoxComposite_MoveCursor(i32x _iCase);
- func void EditBoxComposite_MoveCursorSelect(i32x _iCase);
- func void EditBoxComposite_OnMouseMove(i32x _iX, i32x _iY);
- func void EditBoxComposite_OnGainFocus();
- func void EditBoxComposite_OnMouseDblClick();
- func void EditBoxComposite_OnEnable();
- func void EditBoxComposite_OnDisable();
-
- // msg edit box composite
- func void EditBoxComposite_ChangeType(i32x _iType);
- func void EditBoxComposite_Resize(i32x _iX, i32x _iY);
- func void EditBoxComposite_NbCharAccepted(i32x _iSize);
- func void EditBoxComposite_Text(szx _szTxt);
- func void EditBoxComposite_SaveData(szx _szTxt, i32x _iChangeBox);
- func void EditBoxComposite_Align(i32x _eHAlign, i32x _eVAlign);
- func void EditBoxComposite_ChangeColor(i32x _iColor);
-
-
-
- // Message handling interface
- interface Gui_iBitmapEditBox
- {
- // Gui System Messages
- EditBox_OnMouseMove MouseMove;
- EditBox_OnMouseDown MouseDown;
- EditBox_OnMouseUp MouseUp;
- EditBox_OnMouseClick MouseClick;
- EditBox_OnMouseDblClick MouseDblClick;
- EditBox_OnKeyDown KeyDown;
- EditBox_OnChar Char;
- EditBox_OnLoseFocus LoseFocus;
- EditBox_OnGainFocus GainFocus;
- EditBox_OnKeyUp KeyUp;
- EditBox_Text EbText; // write text in edit box
- EditBox_ChangeType EbChangeType; // change edit box type
- EditBox_NbCharAccepted EbNbCharAccepted; // change number of character accepted in edit box
- EditBox_Resize EbResize; // change size of edit box
- }
-
- interface Gui_iEditBoxComposite
- {
- // Gui System Messages
- EditBoxComposite_OnEnable Enable;
- EditBoxComposite_OnDisable Disable;
-
- EditBoxComposite_OnClick EbCClick;
- EditBoxComposite_OnMouseDblClick EbCDblClick;
- EditBoxComposite_OnLoseFocus EbCLoseFocus;
- EditBoxComposite_OnGainFocus EbCGainFocus;
- EditBoxComposite_Text EbCText; // write text in edit box
- EditBoxComposite_ChangeType EbCChangeType; // change edit box type
- EditBoxComposite_NbCharAccepted EbCNbCharAccepted; // change number of character accepted in edit box
- EditBoxComposite_MoveCursor EbCMoveCursor; // move cursor
- EditBoxComposite_MoveCursorSelect EbCMoveCursorSelect; // move cursor select
- EditBoxComposite_OnMouseMove EbCMouseMove;
- EditBoxComposite_SaveData EbCSaveData; // save edit box data
- EditBoxComposite_Resize EbCResize; // change size of edit box
- EditBoxComposite_Align EbCAlign; // change default align of edit box
- EditBoxComposite_ChangeColor EbCChangeColor; // change edit box color
- }
-
- /*
- * Function : EditBox extented constructor
- * Parameters : _pMaterial material pointer, iColor : background color, fFontSize : font size
- */
- func Gui_Component NewEditBoxExt(Menu_Material _pFont, i32x _iColor, f32x _fFontSize)
- {
- var f32x factor;
- var Menu_Sprite sprite;
- var Gui_Component cursor,editbox,texture,composite;
- var i32x iArea;
- var i32x sx,sy;
- var Gui_dtEditBox pdtEditBox;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
-
- // Create an object that will contain Bitmap buton + caption
- composite = NewObject(Gui_iEditBoxComposite);
-
- // Two component in composite edit box
- SetComponentNumber(composite,2);
-
- // Create container with editbox interface
- editbox = NewContainer(Gui_iBitmapEditBox);
-
- // Create a sprite with material and area index e_GUI_State_Enabled
- sprite = NewSprite2D(_pFont);
- iArea = e_GUI_State_Enabled;
- SetArea(sprite,iArea);
-
- // Get size of Carriage Return for editbox height
- sx = 120.0*g_fScreenScaleFactor;
-
- //change font size
- SetScale(editbox,_fFontSize*g_fScreenScaleFactor);
-
- // calcul editbox size
- factor = (_fFontSize*g_fScreenScaleFactor) / 1.0;
- sy = PrecalcTextHeight(sprite," ") * factor;
-
- // align
- SetAlign(editbox,e_GUI_HAlign_Right,e_GUI_VAlign_Center);
-
- // Attach the sprite to this container
- AttachSprite(editbox,sprite);
-
- // Tell Gui to clip this sprite to container size
- Clip(editbox);
-
- // Affect data pointer
- pdtEditBox = new Gui_dtEditBox;
- pdtEditBox.bWrite = false;
- pdtEditBox.bShift = false;
- pdtEditBox.iCursor = 0;
- pdtEditBox.iCursorEndSelect = 0;
- pdtEditBox.iMaxChar = 20;
- pdtEditBox.szTxt = "";
- pdtEditBox.iType = e_GUI_EditBox_All;
- SetData(editbox,pdtEditBox);
-
- // Create a cursor
- cursor = NewBitmap(smWhite,0);
- SetAlign(cursor,e_GUI_HAlign_Zoom,e_GUI_VAlign_Zoom);
- StretchTo(cursor,2,sy);
-
- // Disable cursor
- cursor<<Disable();
- cursor<<Hide();
-
- // Create background texture
- texture = NewBitmap(smWhite,0);
- Clip(texture);
- SetShadingMode(GetSprite(texture),DLC_GouraudMode_ModulateDiffuse,DLC_GouraudMode_ModulateDiffuse);
- SetBlendingMode(GetSprite(texture),DLC_Blend_AlphaBlend);
- SetColor(texture,_iColor);
- SetAlign(texture,e_GUI_HAlign_Zoom,e_GUI_VAlign_Zoom);
- StretchTo(texture,sx ,sy+(2*g_fScreenScaleFactor));
- // Disable texture
- if(_iColor==0)
- {
- texture<<Hide();
- }
- texture<<Disable();
-
- // Mount containers into object
- MountComponent(composite,texture);
- MountComponent(composite,editbox);
- MountComponent(composite,cursor);
-
- // Affect data pointer
- pdtEditBoxComposite = new Gui_dtEditBoxComposite;
- pdtEditBoxComposite.gcCursor = cursor;
- pdtEditBoxComposite.gcEditBox = editbox;
- pdtEditBoxComposite.gcTexture = texture;
- pdtEditBoxComposite.iLenghtCursor = 2;
- pdtEditBoxComposite.iHeightCursor = sy;
- pdtEditBoxComposite.iHAlign = e_GUI_HAlign_Right;
- pdtEditBoxComposite.iVAlign = e_GUI_VAlign_Center;
- pdtEditBoxComposite.iFocused = 0;
- pdtEditBoxComposite.fFontFactor = factor;
- SetData(composite,pdtEditBoxComposite);
-
- // Strech edit box
- sy = sy+(2*g_fScreenScaleFactor);
- StretchTo(editbox,sx,sy);
-
- // Stretch composite to fit editbox
- StretchTo(composite,sx,sy);
-
- return composite;
- }
-
- /*
- * Function : EditBox constructor with cursor
- * Parameters : _pMaterial material pointer
- */
- func Gui_Component NewEditBox(Menu_Material _pFont, i32x _iColor)
- {
- var f32x fFontSize;
-
- fFontSize = 1.0/g_fScreenScaleFactor;
-
- return NewEditBoxExt(_pFont,_iColor,fFontSize);
- }
-
-
- ////////////////// EVENT EDIT BOX //////////////////////////////////
- /*
- * Function : EditBox key up move callback
- */
- func i32x EditBox_OnKeyUp(i32x _iKey) {
- var Gui_Component pthis;
- var Gui_dtEditBox pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
-
- if (_iKey == VK_Shift) // shift
- pdtEditBox.bShift = false;
- pdtEditBox.bWrite = false;
- }
-
- /*
- * Function : EditBox Mouse move callback
- * Remarks : test if click down
- */
- func i32x EditBox_OnMouseMove(i32x _iX,i32x _iY) {
- var Gui_Component pthis;
- var Gui_Component parent;
- var Gui_dtEditBox pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
-
- if (pdtEditBox.bClick==true) {
- parent = GetParent(pthis);
- parent<<EbCMouseMove(_iX,_iY);
- return 1;
- }
- return 0;
- }
-
- /*
- * Function : EditBox Mouse down callback
- * Remarks : test left click
- */
- func i32x EditBox_OnMouseDown(i32x _iX,i32x _iY,i32x _iButton) {
- var Gui_Component pthis;
- var Gui_dtEditBox pdtEditBox;
-
- if(_iButton == e_Gui_Mouse_Left_Button)
- {
- // msg click send to parent
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- pdtEditBox.bClick = true;
- pdtEditBox.iCursorEndSelect = pdtEditBox.iCursor;
- return 1;
- }
- return 0;
- }
-
- /*
- * Function : EditBox Mouse up callback
- */
- func i32x EditBox_OnMouseUp(i32x _iX,i32x _iY,i32x _iButton) {
- var Gui_Component pthis;
- var Gui_dtEditBox pdtEditBox;
-
- // msg click send to parent
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- if (pdtEditBox.iCursorEndSelect == pdtEditBox.iCursor) pdtEditBox.bClick = false;
- return 1;
- }
-
- /*
- * Function : EditBox Lose Focus callback
- * Remarks : return true
- */
- func i32x EditBox_OnLoseFocus()
- {
- var Gui_Component pthis;
- var Gui_Component parent;
-
- pthis = GetThis();
- parent = GetParent(pthis);
-
- // send mesg to parent
- parent<<EbCLoseFocus();
- return 1;
- }
-
- /*
- * Function : EditBox Gain Focus callback
- * Remarks : return true
- */
- func i32x EditBox_OnGainFocus()
- {
- var Gui_Component pthis;
- var Gui_Component parent;
-
- pthis = GetThis();
- parent = GetParent(pthis);
-
- // send mesg to parent
- parent<<EbCGainFocus();
- return 1;
- }
-
- /*
- * Function : EditBox Mouse click callback
- * Remarks : Test left click
- */
- func i32x EditBox_OnMouseClick(i32x _iX,i32x _iY,i32x _iButton)
- {
- var Gui_Component pthis;
- var Gui_Component parent;
- var Gui_dtEditBox pdtEditBox;
-
- if(_iButton == e_Gui_Mouse_Left_Button)
- {
- // msg click send to parent
- pthis = GetThis();
- parent = GetParent(pthis);
- pdtEditBox = GetData(pthis);
- if (pdtEditBox.bClick == false) {
- parent<<EbCClick(_iX,_iY,_iButton);
- }
- else pdtEditBox.bClick = false;
- return 1;
- }
- return 0;
- }
-
- /*
- * Function : EditBox Mouse double click callback
- * Remarks : Test left click
- */
- func i32x EditBox_OnMouseDblClick(i32x _iX,i32x _iY,i32x _iButton)
- {
- var Gui_Component pthis;
- var Gui_Component parent;
-
- if(_iButton == e_Gui_Mouse_Left_Button)
- {
- // msg click send to parent
- pthis = GetThis();
- parent = GetParent(pthis);
- parent<<EbCDblClick();
- return 1;
- }
- return 0;
- }
-
- /*
- * Function : EditBox Key down callback
- * Remarks : Test Key pressed
- */
- func void EditBox_OnKeyDown(i32x _iKey, i32x _iCount)
- {
- var szx szTxt,szTxtTmp,szTxtTmp2;
- var Gui_Component pthis;
- var Gui_Component parent;
- var Gui_dtEditBox pdtEditBox;
- var i32x iLenghtTxt, iPosTxt;
- var boolx bWrite, bInsert, bShift;
- var i32x iMin, iMax;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- parent = GetParent(pthis);
- pdtEditBox = GetData(pthis);
-
- // init
- iLenghtTxt = strlen(pdtEditBox.szTxt);
- iPosTxt = pdtEditBox.iCursor;
- bInsert = pdtEditBox.bInsert;
- szTxt = strncpy(pdtEditBox.szTxt,0,iLenghtTxt);
- bWrite = true; // si α faux : ne pas effacer la selection dasn l'edit box, et ne rien ecrire au moment du OnChar
- bShift = pdtEditBox.bShift;
-
- if (_iKey == VK_Shift) { // shift
- bWrite = false;
- bShift = true;
- }
- if (_iKey == VK_Left) { // left arrow
- // on recule la position de notre curseur
- if (bShift) {
- if (pdtEditBox.iCursorEndSelect > 0)
- parent<<EbCMoveCursorSelect(-1);
- }
- else {
- if (iPosTxt > 0)
- parent<<EbCMoveCursor(-1);
- }
- bWrite = false;
- }
- if (_iKey == VK_Right) { // right arrow
- // on avance la position de notre curseur si on n'est pas dΘjα au bout du texte
- if (bShift) {
- if (iLenghtTxt > pdtEditBox.iCursorEndSelect)
- parent<<EbCMoveCursorSelect(1);
- }
- else {
- if (iLenghtTxt > iPosTxt)
- parent<<EbCMoveCursor(1);
- }
- bWrite = false;
- }
- if (_iKey == VK_Return || _iKey==VK_Tab) { // enter or tab
- if (pdtEditBox.iType != e_GUI_EditBox_Chat) {
- // save data
- parent<<EbCSaveData(szTxt,e_GUI_EditBox_Change_True);
- bWrite = false;
- }
- }
- if (_iKey == VK_Insert) { // insert
- if (bInsert == false) bInsert = true;
- else bInsert = false;
- }
- if (_iKey >= VK_F1 && _iKey <= VK_F12) { // les touches F1 α F12
- bWrite = false;
- }
- if ((pdtEditBox.iType == e_GUI_EditBox_CharOnly)
- && ((_iKey >= VK_0 && _iKey <= VK_9)
- || (_iKey >= VK_Numpad0 && _iKey <= VK_Numpad9))) { // les touches numeriques alors qu'on est en CharOnly
- bWrite = false;
- }
-
- if (pdtEditBox.iCursorEndSelect != iPosTxt && bWrite == true) { // delete text select in edit box
- if (pdtEditBox.iCursorEndSelect < iPosTxt) {
- iMin = pdtEditBox.iCursorEndSelect;
- iMax = iPosTxt;
- }
- else {
- iMax = pdtEditBox.iCursorEndSelect;
- iMin = iPosTxt;
- }
- // on efface le texte selectionnΘ
- szTxtTmp = strncpy(szTxt,0,iMin);
- szTxtTmp2 = strncpy(szTxt,iMax,iLenghtTxt);
- szTxt = strcat(szTxtTmp,szTxtTmp2);
- // on recule la position de notre curseur
- parent<<EbCMoveCursor(iMin-iPosTxt);
- // on ecrit le nouveau texte
- EditBox_SetText(pthis,pdtEditBox,szTxt);
- }
- else { // if no text select
- if (_iKey == VK_Back) { // backspace
- // si il reste plus d'une lettre
- if (iPosTxt > 0 && iLenghtTxt > 1) {
- // on efface le texte au niveau du curseur
- szTxtTmp = strncpy(szTxt,0,(iPosTxt-1));
- szTxtTmp2 = strncpy(szTxt,iPosTxt,iLenghtTxt);
- szTxt = strcat(szTxtTmp,szTxtTmp2);
- // on recule la position de notre curseur
- parent<<EbCMoveCursor(-1);
- }
- // sinon
- else if (iLenghtTxt < 2) {
- szTxt = " ";
- if (iPosTxt != 0) parent<<EbCMoveCursor(-1);
- }
- // on ecrit le nouveau texte
- EditBox_SetText(pthis,pdtEditBox,szTxt);
- bWrite = false;
- }
- if (_iKey == VK_Delete || (bInsert == true && _iKey >= VK_0 && _iKey <= VK_Divide)) { // del or insert mode
- // si il reste plus d'une lettre
- if (iPosTxt < iLenghtTxt) {
- // si il n'y a plus qu'une lettre
- if (iLenghtTxt == 1) {
- szTxt = " ";
- }
- else {
- // on efface le texte au niveau du curseur
- szTxtTmp = strncpy(szTxt,0,iPosTxt);
- szTxtTmp2 = strncpy(szTxt,(iPosTxt+1),(iLenghtTxt-1));
- szTxt = strcat(szTxtTmp,szTxtTmp2);
- }
- // on ecrit le nouveau texte
- EditBox_SetText(pthis,pdtEditBox,szTxt);
- }
- }
- }
-
- pdtEditBox.bInsert = bInsert;
- pdtEditBox.bWrite = bWrite;
- pdtEditBox.bShift = bShift;
- }
-
- /*
- * Function : EditBox key pressed callback
- * Remarks : Test if write == true
- */
- func void EditBox_OnChar(szx _szChar,i32x _iCount)
- {
- var szx szTxtTmp, szTxtTmp2, szTxt;
- var Gui_Component pthis;
- var Gui_Component parent;
- var Gui_dtEditBox pdtEditBox;
- var i32x iLenghtTxt, iPosTxt;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- parent = GetParent(pthis);
- pdtEditBox = GetData(pthis);
-
- // test au cas o∙ on aurait appuyΘ sur une touche caracteres alors qu'on est en Numeric
- if (pdtEditBox.iType == e_GUI_EditBox_Numeric) {
- if (strcmp(_szChar,"0")!=0
- && strcmp(_szChar,"1")!=0
- && strcmp(_szChar,"2")!=0
- && strcmp(_szChar,"3")!=0
- && strcmp(_szChar,"4")!=0
- && strcmp(_szChar,"5")!=0
- && strcmp(_szChar,"6")!=0
- && strcmp(_szChar,"7")!=0
- && strcmp(_szChar,"8")!=0
- && strcmp(_szChar,"9")!=0
- && strcmp(_szChar,".")!=0
- && strcmp(_szChar,"-")!=0)
- pdtEditBox.bWrite = false;
- }
- // init
- iLenghtTxt = strlen(pdtEditBox.szTxt);
- iPosTxt = pdtEditBox.iCursor;
- szTxt = strncpy(pdtEditBox.szTxt,0,iLenghtTxt);
-
- if (pdtEditBox.bWrite && iLenghtTxt < pdtEditBox.iMaxChar) { // if not backspace
- // on recupere tout le texte jusqu'a la position de notre curseur
- szTxtTmp = strncpy(szTxt,0,iPosTxt);
- szTxtTmp = strcat(szTxtTmp,_szChar);
- // si la taille du texte est plus grande que la valeur de la position de notre curseur
- // alors il ya du texte α remettre
- if (iLenghtTxt > iPosTxt) {
- szTxtTmp2 = strncpy(szTxt,iPosTxt,iLenghtTxt);
- szTxtTmp = strcat(szTxtTmp,szTxtTmp2);
- }
- // on ecrit le nouveau texte
- EditBox_SetText(pthis,pdtEditBox,szTxtTmp);
- // on avance notre curseur
- parent<<EbCMoveCursor(1);
- }
- }
-
- /////////////////////////////////////////// END EVENT EDIT BOX /////////////////////////////
-
-
- /////////////////////////////////////////// EVENT EDIT BOX COMPOSITE /////////////////////////////
-
- /*
- * Function : EditBoxComposite mouse click callback
- */
- func void EditBoxComposite_OnClick(i32x _iX,i32x _iY,i32x _iButton) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
- var i32x iCase, iLenghtTxt, iWidth, iWidthNext,iSign;
- var f32x factor;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
-
- // calcul du nombre de case α se dΘplacer
- factor = pdtEditBoxComposite.fFontFactor;
- iCase = pdtEditBox.iCursor;
- iWidthNext = 0.5 + (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,iCase,1)) / 2.0) * factor;
- _iX = _iX-(AbsPosX(pdtEditBoxComposite.gcCursor)+iWidthNext);
- if (_iX < 0) {
- _iX = abs(_iX) - iWidthNext;
- iWidthNext = 0.5 + (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,(iCase-1),1)) / 2.0) * factor;
- _iX = _iX - iWidthNext;
- iSign = -1;
- }
- else iSign =1;
-
- // boucle jusqu'α se qu'on dΘpasse la position du curseur
- while (_iX > 0) {
- iCase = iCase + iSign;
- iWidth = iWidthNext;
- iWidthNext = 0.5 + (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,iCase,1)) / 2.0) * factor;
- _iX = _iX - iWidth - iWidthNext;
- }
-
- // dΘplacement en fonction d'o∙ on a cliquΘ
- iLenghtTxt = strlen(pdtEditBox.szTxt);
- if (iCase > iLenghtTxt) {
- pthis<<EbCMoveCursor(iLenghtTxt-pdtEditBox.iCursor);
- }
- else if (iCase >= 0)
- pthis<<EbCMoveCursor(iCase-pdtEditBox.iCursor);
- }
-
- /*
- * Function : EditBox mouse double click callback
- */
- func void EditBoxComposite_OnMouseDblClick() {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
-
- // booleen click = true pour indiquer qu'il y a une selection
- pdtEditBox.bClick = true;
- // on ramene le curseur au debut de l'edit box
- pthis<<EbCMoveCursor(-pdtEditBox.iCursor);
- // on selectionne tout
- pthis<<EbCMoveCursorSelect(strlen(pdtEditBox.szTxt));
- }
-
- /*
- * Function : lose focus EditBox => hide caption
- */
- func void EditBoxComposite_OnLoseFocus()
- {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBoxComposite.gcCursor<<Hide();
- // pdtEditBoxComposite.gcTexture<<Hide();
- pdtEditBoxComposite.iFocused = 0;
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
- pthis<<EbCSaveData(pdtEditBox.szTxt,e_GUI_EditBox_Change_False);
- // Reset horizontal align
- SetAlign(pdtEditBoxComposite.gcEditBox,pdtEditBoxComposite.iHAlign,pdtEditBoxComposite.iVAlign);
- }
-
- /*
- * Function : gain focus EditBox => show caption
- */
- func void EditBoxComposite_OnGainFocus() {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBoxComposite.gcCursor<<Show();
- // if(GetColor(pdtEditBoxComposite.gcTexture) != 0)
- // pdtEditBoxComposite.gcTexture<<Show();
- pdtEditBoxComposite.iFocused = 1;
- // Set horizontal align
- SetAlign(pdtEditBoxComposite.gcEditBox,e_GUI_HAlign_Left,e_GUI_VAlign_Center);
- }
-
-
- /*
- * Function : EditBox Mouse Move callback (only if mouse click is down)
- */
- func void EditBoxComposite_OnMouseMove(i32x _iX, i32x _iY) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
- var i32x iCase, iLenghtTxt, iPos, iWidth, iWidthNext, iSizeX, iSign;
- var f32x factor;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
-
- // calcul de la largeur du curseur
- iSizeX = SizeX(pdtEditBoxComposite.gcCursor);
-
- // calcul du deplacement de la souris par rapport au curseur
- factor = pdtEditBoxComposite.fFontFactor;
- iCase = pdtEditBox.iCursorEndSelect;
- iWidthNext = 0.5 + (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,iCase,1)) / 2.0) * factor;
- _iX = _iX-(AbsPosX(pdtEditBoxComposite.gcCursor)+iWidthNext+iSizeX);
-
- if (_iX < 0) { // si on a reculΘ par rapport au curseur
- _iX = abs(_iX) - iWidthNext;
- iWidthNext = 0.5 + (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,(iCase-1),1)) / 2.0) * factor;
- _iX = _iX - iWidthNext;
- iSign = -1;
- }
- else iSign = 1;
-
- // calcul du nombre de case qui separe notre curseur du dΘplacement de la souris
- while (_iX > 0) {
- iCase = iCase + iSign;
- iWidth = iWidthNext;
- iWidthNext = 0.5 + (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,iCase,1)) / 2.0) * factor;
- _iX = _iX - iWidth - iWidthNext;
- }
-
- // on dΘplace le curseur
- iLenghtTxt = strlen(pdtEditBox.szTxt);
- if (iCase > iLenghtTxt)
- pthis<<EbCMoveCursorSelect(iLenghtTxt-pdtEditBox.iCursorEndSelect);
- else if (iCase >= 0)
- pthis<<EbCMoveCursorSelect(iCase-pdtEditBox.iCursorEndSelect);
- }
-
- /////////////////////////////////////////// END EVENT EDIT BOX COMPOSITE /////////////////////////////
-
-
- /////////////////////////////////////////// FUNC EDIT BOX /////////////////////////////
-
- /*
- * Function : write text in EditBox
- */
- func void EditBox_SetText(Gui_Component _pthis, Gui_dtEditBox _pdtEditBox, szx _szTxt)
- {
- var Menu_Sprite msSprite;
-
- // text -> sprite
- msSprite = GetSprite(_pthis);
-
- SetText(msSprite,_szTxt);
-
- // text -> edit box class
- _pdtEditBox.szTxt = strncpy(_szTxt,0,strlen(_szTxt));
- }
-
- func szx EditBox_GetText(Gui_Component _pComponent)
- {
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
-
- // get Data
- pdtEditBoxComposite = GetData(_pComponent);
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
-
- return (pdtEditBox.szTxt);
- }
-
- /////////////////////////////////////////// END FUNC EDIT BOX /////////////////////////////
-
-
- /////////////////////////////////////////// MSG EDIT BOX //////////////////////////////////
-
- /*
- * Function : write text in EditBox
- * Remarks : call this function with message EbText (message only call when we wish put a new text)
- */
- func void EditBox_Text(szx _szTxt) {
- var Gui_Component pthis, parent;
- var Gui_dtEditBox pdtEditBox;
-
- pthis = GetThis();
- parent = GetParent(pthis);
- pdtEditBox = GetData(pthis);
-
- // move cursor at the begin of word
- pdtEditBox.iCursor = 0;
-
- // set the text
- EditBox_SetText(pthis,pdtEditBox,_szTxt);
- }
-
- /*
- * Function : change edit box type
- */
- func void EditBox_ChangeType(i32x _iType) {
- var Gui_Component pthis;
- var Gui_dtEditBox pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- pdtEditBox.iType = _iType;
- }
-
- /*
- * Function : change number of character accepted in edit box
- */
- func void EditBox_NbCharAccepted(i32x _iSize) {
- var Gui_Component pthis;
- var Gui_dtEditBox pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- pdtEditBox.iMaxChar = _iSize;
- }
-
- /*
- * Function : change size of edit box
- */
- func void EditBox_Resize(i32x _iX, i32x _iY) {
- var Gui_Component pthis;
-
- pthis = GetThis();
- StretchTo(pthis,_iX,_iY);
- }
-
-
- ///////////////////////////////////////END MSG EDIT BOX /////////////////////////////
-
-
- /////////////////////////////////////////// MSG EDIT BOX COMPOSITE /////////////////////////////
-
- /*
- * Function : save data
- */
- func void EditBoxComposite_SaveData(szx _szTxt, i32x _iChangeBox) {
- var Gui_Component parent;
- var Gui_Component pthis;
-
- pthis = GetThis();
- parent = GetParent(pthis);
- parent<<SaveData(pthis,_szTxt,_iChangeBox);
- }
-
- /*
- * Function : write text in EditBox
- * Remarks : call this function with message EbCText (message only call when we wish put a new text)
- */
- func void EditBoxComposite_Text(szx _szTxt)
- {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
-
- // move cursor at the begin of EditBox
- Move(pdtEditBox.gcCursor,-RelPosX(pdtEditBox.gcCursor),0);
-
- // Set Text
- pdtEditBox.gcEditBox<<EbText(_szTxt);
-
- // move at the end of text
- pthis<<EbCMoveCursor(strlen(_szTxt));
- }
-
- /*
- * Function : change edit box type
- */
- func void EditBoxComposite_ChangeType(i32x _iType) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- pdtEditBox.gcEditBox<<EbChangeType(_iType);
- }
-
- /*
- * Function : change number of character accepted in edit box
- */
- func void EditBoxComposite_NbCharAccepted(i32x _iSize) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- pdtEditBox.gcEditBox<<EbNbCharAccepted(_iSize);
- }
-
- /*
- * Function : change size of edit box
- */
- func void EditBoxComposite_Resize(i32x _iX, i32x _iY) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- StretchTo(pthis,_iX,_iY);
- // resize texture
- StretchTo(pdtEditBox.gcTexture,_iX,_iY);
- // resize editbox
- pdtEditBox.gcEditBox<<EbResize(_iX,_iY);
- }
-
- /*
- * Function : change alignement of edit box
- */
- func void EditBoxComposite_Align(i32x _eHAlign, i32x _eVAlign)
- {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
- // Change default align
- pdtEditBox.iHAlign = _eHAlign;
- pdtEditBox.iVAlign = _eVAlign;
-
- // Change align if not focused
- if(pdtEditBox.iFocused == 0)
- {
- SetAlign(pdtEditBox.gcEditBox,_eHAlign,_eVAlign);
- }
- }
-
- /*
- * Function : change color of edit box
- */
- func void EditBoxComposite_ChangeColor(i32x _iColor)
- {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBox;
-
- pthis = GetThis();
- pdtEditBox = GetData(pthis);
-
- // Change default color
- SetColor(pdtEditBox.gcTexture,_iColor);
- }
-
-
- /*
- * Function : move cursor
- */
- func void EditBoxComposite_MoveCursor(i32x _iCase) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
- var i32x iMove, iStart, iSign;
- var f32x factor;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
-
- if (_iCase != 0) {
- if (_iCase > 0) {
- iSign = 1;
- iStart = pdtEditBox.iCursor;
- }
- else {
- iStart = pdtEditBox.iCursor + _iCase;
- iSign = -1;
- }
- // calcul de la distance α parcourir avec le curseur
- factor = pdtEditBoxComposite.fFontFactor;
- iMove = iSign * (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,iStart,abs(_iCase))) * factor + 0.5);
- // on deplace le curseur dans la structure
- pdtEditBox.iCursor = pdtEditBox.iCursor + _iCase;
- }
- else iMove = 0;
- // on enleve la selection au cas o∙ il y en avait une
- pdtEditBox.iCursorEndSelect = pdtEditBox.iCursor;
- // on redimensionne le curseur α sa taille par dΘfaut
- StretchTo(pdtEditBoxComposite.gcCursor,pdtEditBoxComposite.iLenghtCursor,pdtEditBoxComposite.iHeightCursor);
- // on deplace le curseur α l'ecran
- Move(pdtEditBoxComposite.gcCursor,iMove,0);
- }
-
- /*
- * Function : move cursor select
- */
- func void EditBoxComposite_MoveCursorSelect(i32x _iCase) {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
- var Gui_dtEditBox pdtEditBox;
- var i32x iMove, iStart, iSign, iSizeX;
- var f32x factor;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- pdtEditBox = GetData(pdtEditBoxComposite.gcEditBox);
-
- if (_iCase >= 0) {
- iStart = pdtEditBox.iCursorEndSelect;
- iSign = 1;
- }
- else {
- iStart = pdtEditBox.iCursorEndSelect + _iCase;
- iSign = -1;
- }
- // calcul de la distance α couvrir
- factor = pdtEditBoxComposite.fFontFactor;
- iMove = SizeX(pdtEditBoxComposite.gcCursor) +
- (iSign * (PrecalcTextWidth(GetSprite(pdtEditBoxComposite.gcEditBox),strncpy(pdtEditBox.szTxt,iStart,abs(_iCase))) * factor + 0.5));
- // on deplace le curseur de selection dans la structure
- pdtEditBox.iCursorEndSelect = pdtEditBox.iCursorEndSelect + _iCase;
-
- // on etire le curseur
- StretchTo(pdtEditBoxComposite.gcCursor,iMove,pdtEditBoxComposite.iHeightCursor);
- }
-
- func void EditBoxComposite_OnEnable()
- {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- // Update background color
- SetColor(pdtEditBoxComposite.gcTexture,cEBColor);
- }
- func void EditBoxComposite_OnDisable()
- {
- var Gui_Component pthis;
- var Gui_dtEditBoxComposite pdtEditBoxComposite;
-
- // on recupere les donnees du container actif
- pthis = GetThis();
- pdtEditBoxComposite = GetData(pthis);
- // Update background color
- SetColor(pdtEditBoxComposite.gcTexture,cEBDisableColor);
- }
-
- /////////////////////////////////////////// END MSG EDIT BOX COMPOSITE /////////////////////////////
-